package com.guang.springmybatis.beanfactory;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Description
 * @Author liguang
 * @Date 2022/08/23/21:24
 */
public class LGBeanFactory implements FactoryBean {


    private Class mapperInterface;

    public LGBeanFactory(Class mapperInterface) {
        this.mapperInterface = mapperInterface;
    }

    /**
     * 产生代理对象并返回
     * @return
     * @throws Exception
     */
    @Override
    public Object getObject() throws Exception {
        Object mapperInterfaceProxy = Proxy.newProxyInstance(LGBeanFactory.class.getClassLoader(), new Class[]{mapperInterface}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                return null;
            }
        });
        return mapperInterfaceProxy;
    }

    @Override
    public Class<?> getObjectType() {
        return mapperInterface;
    }
}
